package com.kxs.stu_manager;

import com.kxs.stu_manager.controller.UserController;
import com.kxs.stu_manager.global.User;
import com.kxs.stu_manager.model.UserModel;
import com.kxs.stu_manager.views.StuPage;
import com.kxs.stu_manager.views.UserPage;

import java.sql.SQLException;
import java.util.ArrayList;

/**
 * @ClassName StuManagerMain
 * @Description: TODO 主方法类
 * @Author: 2119475835@qq.com
 * @Date: 2023/1/9
 */
public class StuManagerMain {
    public static void main(String[] args) throws SQLException {
        UserController uc = new UserController();
        UserModel um = new UserModel();
        // 通过用户页面获取用户操作数
        // 将操作数传入总调度器并且返回一个用户
        User user = uc.loginAction(UserPage.welcome());
        if(null != user){
            UserPage.welcomeToBack(user.getUserName());
        }else{
            UserPage.failed("注册或登录失败！~");
            System.exit(-1);
        }

        while (true){
            // 进行数据的刷新
            try{
                ArrayList<User> userList = um.getUserInfoByName(user.getUserName());
                uc.userOrStuAction(UserPage.superManagerPage(userList.get(0).getCompetence()),
                                                            userList.get(0).getCompetence());
            }catch (Exception e){
                StuPage.failed("用户不存在，退出系统！~");
                System.exit(-1);
            }
        }

    }
}
